import Vue from 'vue'
import Vuex from 'vuex'
import products from './modules/products'
import user from './modules/user'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    count: 1,
    message: '我是state_message!',
    msg: '我是state_msg'
  },
  getters:{
    msgReverse:state => {
      return state.msg.split('').reverse().join("");
    }
  },
  mutations: {
    increment:(state, payload) => {
      state.count += payload
    } 
  },
  actions: {
    incrementAsync:({commit},payload) => {
      setTimeout(()=>{
        commit('increment', payload)
      },1000)
    }
  },
  modules: {
    products,
    user
  }
})
